<template>
	<view v-if="width" :style="'width:'+width+';'+(square?'height:'+width:'')" class="uni-grid-item">
		<view :class="{ 'kun-grid-item--border': showBorder,  'kun-grid-item--border-top': showBorder && index >= column, 
		'kun-highlight': highlight,'kun-grid-item--border-left-none':index%column==0 }"
		 :style="{  'border-right-color': borderColor ,'border-bottom-color': borderColor ,'border-top-color': borderColor }"
		 class="kun-grid-item__box" @click="_onClick">
			<slot />
		</view>
	</view>
</template>

<script>
	export default {
		name: 'KGridItem',
		inject: ['grid'],
		props: {
			index:{
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				column: 0,
				showBorder: true,
				square: true,
				highlight: true,
				left: 0,
				top: 0,
				openNum: 2,
				width: 0,
				borderColor: '#e5e5e5'
			}
		},
		created() {
			this.column = this.grid.column
			this.showBorder = this.grid.showBorder
			this.square = this.grid.square
			this.highlight = this.grid.highlight
			this.top = this.hor === 0 ? this.grid.hor : this.hor
			this.left = this.ver === 0 ? this.grid.ver : this.ver
			this.borderColor = this.grid.borderColor
			this.grid.children.push(this)
			// this.grid.init()
			this.width = this.grid.width
		},
		beforeDestroy() {
			this.grid.children.forEach((item, index) => {
				if (item === this) {
					this.grid.children.splice(index, 1)
				}
			})
		},
		methods: {
			_onClick() {
				this.grid.change({
					detail: {
						index: this.index
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import '../../init.scss';
	.uni-grid-item {
		height: 100%;
		display: flex;
	}

	.kun-grid-item__box {
		display: flex;
		width: 100%;
		position: relative;
		flex: 1;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.kun-grid-item--border {
		position: relative;
		// border-bottom-color: $k-border-color;
		// border-bottom-style: solid;
		// border-bottom-width: 1px;
		// border-right-color: $k-border-color;
		// border-right-style: solid;
		// border-right-width: 1px;
		border-left: 1px solid $k-border-color;
		
	}
	.kun-grid-item--border-left-none{
		border-left: none;
	}

	.kun-grid-item--border-top {
		border-top-color: $k-border-color;
		border-top-style: solid;
		border-top-width: 1px;
		height: 100%;		
		box-sizing: border-box;
	}

	.kun-highlight:active {
		background-color: $k-bg-color-hover;
	}
</style>
